﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;

namespace StatusPlan3.UC
{
    /// <summary>
    /// Interaction logic for UCTasks.xaml
    /// </summary>
    public partial class UCTasks : UserControl
    {
        public ProjectGroup projectGroup;
        public Project project;
        public RadPane rp;

        public UCTasks()
        {
            InitializeComponent();
        }

        public void setData(Project p, ProjectGroup pg) 
        {
            projectGroup = pg;
            project = p;

            populateFrame();
        }

        public void populateFrame()
        {
            project = StatusPlanData.statusPlanHandler.getProject(project.id);

            TextBlock_ProjectGroupName.Text = projectGroup.name;
            TextBlock_ProjectName.Text = project.name;

            Tasks tasks = new Tasks();

            foreach (Task t in project.tasks)
                tasks.Add(t);

            foreach (Subproject sp in project.subproject)
                foreach(Task t in sp.tasks)
                    tasks.Add(t);

            taskGridView.ItemsSource = tasks;

            //Load Messages;
            UC.UCMessages ucMessages = new UC.UCMessages(project.messages);
            ucMessages.project = this;
            MessageGroupBox.Content = ucMessages;

            //Load Files
            UC.UCFiles ucFiles = new UCFiles(project.attachedFiles);
            FileGroupBox.Content = ucFiles;
            ucFiles.ucProject = this;
        }

        public void refreshFrame()
        {
            populateFrame();
        }

        private void taskGridView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Task t = taskGridView.SelectedItem as Task;
            StatusPlanData.mainWindow.showTask(t, project, projectGroup);
        }

        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            if (FileGroupBox.Visibility == System.Windows.Visibility.Collapsed)
            {
                Splitter.Visibility = System.Windows.Visibility.Visible;
                FileGroupBox.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                Splitter.Visibility = System.Windows.Visibility.Collapsed;
                FileGroupBox.Visibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void Splitter_MouseEnter(object sender, MouseEventArgs e)
        {
            Splitter.Background = new SolidColorBrush(Colors.LightBlue);
        }

        private void Splitter_MouseLeave(object sender, MouseEventArgs e)
        {
            Splitter.Background = new SolidColorBrush(Colors.Transparent);
        }


    }
}
